#include<bits/stdc++.h>
using namespace std;
#define int long long
inline int read(){
	int x=0,f=1;
	char c=getchar();
	while(!isdigit(c)){
		if(c=='-')f=-1;
		c=getchar();
	}
	while(isdigit(c)){
		x=(x<<1)+(x<<3)+(c^48);
		c=getchar();
	}
	return x*f;
}
const int maxn=2e5+5;
int n,a[maxn],c[maxn];
void solve(){
	scanf("%lld",&n);
	for(int i=1;i<=n;i++)scanf("%lld",&a[i]);
	int ans=0;
	for(int i=1;i<=n;i++)c[i]=0;
	for(int s=0;s<(1<<n);s++){
		int sum=0;
		for(int i=1;i<=n;i++){
			for(int j=i-1;j>0;j--){
				if((s>>(i-1)&1)==(s>>(j-1)&1)&&a[i]==a[j]){
					c[j]=a[j];
					break;
				}
			}
		}
		for(int i=1;i<=n;i++)sum+=c[i];
		ans=max(ans,sum);
	}
	cout<<ans<<endl;
}
signed main(){
	freopen("color.in","r",stdin);
	freopen("color.out","w",stdout);
	int T;scanf("%lld",&T);
	while(T--){
		solve();
	}
	return 0;
}
